import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class LuckDraw {

    public static void main(String[] args) {


        List<Integer> integers = new ArrayList<>();
        integers.add(1);

        integers = integers.stream().filter(integer -> integer > 10).collect(Collectors.toList());
        System.out.println(integers);

        System.out.println(integers.indexOf(1));

        System.out.println(integers.remove(new Random().nextInt(integers.size())));



    /*    int count = 0;
        for (int i = 0; i < 100; i++) {
            int num = luckDraw(i);

            if (num != 0) {
                count++;
            }

            List<Integer> list = getPricesList(num, 12);

            System.out.println(list);
        }

        System.out.println("中奖了：" + count + "次");
*/
    }


    /**
     * 获取中奖号
     *
     * @param count 参加抽奖的次数
     * @return 中奖号，0为谢谢惠顾
     */
    public static int luckDraw(int count) {

        //中奖号码，0为谢谢惠顾
        int result = 0;
        //奖池列表
        List<Integer> prices = null;

        if (count <= 3) {
            prices = Arrays.asList(1, 2, 3, 4, 10, 11);
        } else if (count <= 6) {
            prices = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
        } else if (count <= 9) {
            prices = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
        } else {
            prices = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
        }

        //随机数
        int ran = (int) (Math.random() * 100);

        for (Integer price : prices) {
            if (ran == price) {
                result = price;
                break;
            }
        }

        String msg = result == 0 ? "没中奖" : "中奖了";
        System.out.println(msg + " result : " + result);
        return result;
    }

    //TODO 最终奖励列表包括0,1,2,3,4
    /**
     * 获取最终奖励列表（展示给用户看）
     *
     * @param num  中奖号码，0为未中奖
     * @param size 最终列表长度
     * @return 奖励列表
     */
    public static List<Integer> getPricesList(int num, int size) {

        List<Integer> prices = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16));

        if (size > prices.size()) {
            throw new IndexOutOfBoundsException("列表大小不能超过奖池大小 size : " + size + " currentSize : " + prices.size());
        }

        List<Integer> finalList = new ArrayList<>();

        //添加谢谢惠顾进列表
        finalList.add(prices.remove(prices.indexOf(0)));

        if (num != 0) {
            //把中奖号从奖池中移除并放在最终列表中
            finalList.add(prices.remove(prices.indexOf(num)));
        }

        while (finalList.size() != size) {
            finalList.add(prices.remove(new Random().nextInt(prices.size())));
        }

        finalList.sort(Integer::compareTo);

        return finalList;
    }
}
